﻿/*
copyright 2005@crl e_mail:zzmmcrl@163.com;
*/
dynamic class crl.crlContextMenu extends ContextMenu {
	private var customItems:Array;
	private var alert;
	private var isFull:Boolean;
	public function crlContextMenu() {
		this.hideBuiltInItems();
		alert = new Alert();
		ifFull = false;
		customItems.push(new ContextMenuItem("All-Min", Scale));
		customItems.push(new ContextMenuItem("All-Max", Open));
		var a:ContextMenuItem = new ContextMenuItem("Sort(X)", SortX);
		a.separatorBefore = true;
		customItems.push(a);
		customItems.push(new ContextMenuItem("Sort(Y)", SortY));
		customItems.push(new ContextMenuItem("Sort(R)", SortR));
		a = new ContextMenuItem("ClearScreen", Close);
		a.separatorBefore = true;
		customItems.push(a);
	}
	public function hideBuiltInItems():Void {
		super.hideBuiltInItems();
	}
	function Scale() {
		for (var i = 0; i<_root.arr.length; i++) {
			if (!_root.arr[i].isScale) {
				_root.arr[i]._mc.head.scale.onPress();
			}
		}
	}
	function Open() {
		for (var i = 0; i<_root.arr.length; i++) {
			if (_root.arr[i].isScale) {
				_root.arr[i]._mc.head.scale.onPress();
			}
		}
	}
	function Close():Boolean {
		var arr = _root.arr;
		for (var i = arr.length-1; i>=0; i--) {
			arr[i].Clear();
		}
		return true;
	}
	function SortY() {
		var max;
		if (_root.arr.length>1) {
			//首先必须是两个才能比较;
			for (var i = 0; i<_root.arr.length; i++) {
				max = _root.arr[i]._mc._y<_root.arr[i-1]._mc._y ? _root.arr[i]._mc._y : _root.arr[i-1]._mc._y;
				if (max == null) {
					max = 50;
				}
			}
			for (var i = 0; i<_root.arr.length; i++) {
				_root.arr[i]._mc.onEnterFrame = function() {
					this._y += (max-this._y)/3;
					trace(this._y);
					if (Math.abs(max-this._y)<0.6) {
						delete this.onEnterFrame;
					}
				};
			}
		}
	}
	function SortX() {
		var max;
		if (_root.arr.length>1) {
			//首先必须是两个才能比较;
			for (var i = 0; i<_root.arr.length; i++) {
				max = _root.arr[i]._mc._x<_root.arr[i-1]._mc._x ? _root.arr[i]._mc._x : _root.arr[i-1]._mc._x;
			}
			for (var i = 0; i<_root.arr.length; i++) {
				_root.arr[i]._mc.onEnterFrame = function() {
					this._x += (max-this._x)/3;
					if (Math.abs(max-this._x)<.6) {
						delete this.onEnterFrame;
					}
				};
			}
		}
	}
	function SortR() {
		for (var i = 0; i<_root.arr.length; i++) {
			_root.arr[i]._mc.X = random(Stage.width-200);
			_root.arr[i]._mc.Y = random(Stage.height-100);
			_root.arr[i]._mc.onEnterFrame = function() {
				this._x += (this.X-this._x)/3;
				this._y += (this.Y-this._y)/3;
				if (Math.abs(this.X-this._x)<.6) {
					delete this.onEnterFrame;
				}
			};
		}
	}
}
